<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCouponTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable('coupon')) {
            Schema::create('coupon', function (Blueprint $table) {
                $table->increments('id')->comment('优惠券ID');
                $table->string('coupon_name')->default('')->comment('优惠券名称');
                $table->unsignedTinyInteger('coupon_type')->default(10)->comment('优惠券类型(10满减券 20折扣券)');
                $table->decimal('reduce_price', 10, 2)->unsigned()->default(0.00)->comment('满减券-减免金额');
                $table->decimal('discount', 10, 1)->default(0.00)->comment('折扣券-折扣率(0-100)');
                $table->decimal('min_price', 10)->unsigned()->default(0.00)->comment('最低消费金额');
                $table->unsignedTinyInteger('expire_type')->default(10)->comment('到期类型(10领取后生效 20固定时间)');
                $table->unsignedInteger('expire_day')->default(0)->comment('领取后生效-有效天数');
                $table->unsignedInteger('start_time')->nullable()->comment('固定时间-开始时间');
                $table->unsignedInteger('end_time')->nullable()->comment('固定时间-结束时间');
                $table->unsignedTinyInteger('apply_range')->default(10)->comment('适用范围(10全部商品 20指定商品 30排除商品)');
                $table->text('apply_range_config')->nullable()->comment('适用范围配置(json格式)');
                $table->integer('total_num')->default(0)->comment('发放总数量(-1为不限制)');
                $table->unsignedInteger('receive_num')->default(0)->comment('已领取数量');
                $table->string('describe', 500)->default('')->comment('优惠券描述');
                $table->unsignedTinyInteger('status')->default(1)->comment('状态(1显示 0隐藏)');
                $table->unsignedInteger('sort')->default(0)->comment('排序方式(数字越小越靠前)');
                $table->unsignedInteger('store_id')->default(0)->index('store_id')->comment('商城ID');
                $table->unsignedTinyInteger('index_status')->default(0)->comment('首页展示0否1是');
                $table->unsignedInteger('max_receive_num')->default(0)->comment('最大领取数量-1位不限制');
                $table->timestamps();
                $table->softDeletes()->comment('删除时间');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('coupon');
    }
}
